package userapp

import (
	"babyplan/configcenter"
	"babyplan/internal/common/constant"
	"babyplan/internal/common/mt"
	"babyplan/router"
	"cftgo/cftf/db"
	"cftgo/cftf/meta"
)

type userApp struct {
	initCb   func()
	unInitCb func()
}

var _instance = new(userApp)

func Instance() *userApp {
	return _instance
}

func (this *userApp) GetPkgName() string {
	return "login"
}

func (this *userApp) GetHttpListenPort() int32 {
	return mt.Table.BabyPlanCluster.GetListenPort()
}

func (this *userApp) Run(initCb func(), unInitCb func()) {
	this.initCb = initCb
	this.unInitCb = unInitCb
}

func (this *userApp) Init() {
	mt.Table.Init()
	meta.LoadMetaTable(mt.Table)
	configcenter.Init()
	this.registerDataSources()
	router.Init()
}

func (this *userApp) UnInit() {
	router.UnInit()
	mt.Table.UnInit()
	this.unInitCb()
}

func (this *userApp) Update() {
}

func (this *userApp) registerDataSources() {
	db.RegisterOrmDb(
		constant.BABYPLANT_DB,
		configcenter.GetBabyPlanDbConf().Host,
		configcenter.GetBabyPlanDbConf().Port,
		configcenter.GetBabyPlanDbConf().User,
		configcenter.GetBabyPlanDbConf().Passwd,
		configcenter.GetBabyPlanDbConf().DataBase)
}

func (this *userApp) HasTask() bool {
	return false
}
